home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / systty.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-24  |  12.2 KB  |  458 lines

  1. /* systty.h - System-dependent definitions for terminals.
  2.    Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: FSF 19.28. */
  21.  
  22. #ifndef _XEMACS_SYSTTY_H_
  23. #define _XEMACS_SYSTTY_H_
  24.  
  25. #ifdef HAVE_TERMIOS
  26. #define HAVE_TCATTR
  27. #endif
  28.  
  29. /* If we defined these before and we are about to redefine them,
  30.    prevent alarming warnings.  */
  31. #ifdef BSD_TERMIOS
  32. #undef NL0
  33. #undef NL1
  34. #undef CR0
  35. #undef CR1
  36. #undef CR2
  37. #undef CR3
  38. #undef TAB0
  39. #undef TAB1
  40. #undef TAB2
  41. #undef XTABS
  42. #undef BS0
  43. #undef BS1
  44. #undef FF0
  45. #undef FF1
  46. #undef ECHO
  47. #undef NOFLSH
  48. #undef TOSTOP
  49. #undef FLUSHO
  50. #undef PENDIN
  51. #endif
  52.  
  53. /* Include the proper files.  */
  54.  
  55. #if defined (HAVE_TERMIOS)
  56.  
  57. /*****     (1) The TERMIOS way (POSIX style)     *****/
  58.  
  59. # if defined (_AIX) && defined (_I386)
  60. #  include <termios.h>        /* termios.h needs to be before termio.h */
  61. #  include <termio.h>
  62. # else
  63. #  if !defined (NO_TERMIO)
  64. #   include <termio.h>
  65. #  endif
  66. #  include <termios.h>
  67. # endif /* _AIX && _I386 */
  68.  
  69. #elif defined (HAVE_TERMIO)
  70.  
  71. /*****    (2) The TERMIO way (system V style)    *****/
  72.  
  73. # ifdef __DGUX
  74. #  include <sys/ioctl.h>
  75. # endif
  76. # ifndef NO_TERMIO
  77. #  include <termio.h>
  78. # endif /* not NO_TERMIO */
  79.  
  80. #elif defined (MSDOS)
  81.  
  82. /*****             (3) The MSDOS way              *****/
  83.  
  84. /* Nothing doing */
  85.  
  86. #elif !defined (VMS)
  87.  
  88. /*****              (4) The BSD way              *****/
  89.  
  90. # ifdef linux
  91. #  include <bsd/sgtty.h>
  92. # else
  93. #  include <sgtty.h>
  94. # endif
  95.  
  96. #else /* VMS */
  97.  
  98. /*****              (5) The VMS way              *****/
  99.  
  100. # include <descrip.h>
  101. static struct iosb
  102. {
  103.   short status;
  104.   short offset;
  105.   short termlen;
  106.   short term;
  107. } input_iosb;
  108.  
  109. extern int vms_waiting_for_ast;
  110. extern int vms_stop_input;
  111. extern int vms_input_ef;
  112. extern int vms_timer_ef;
  113. extern int vms_process_ef;
  114. extern int vms_input_eflist;
  115. extern int vms_timer_eflist;
  116.  
  117. static $DESCRIPTOR (vms_input_dsc, "TT");
  118. static int vms_terminator_mask[2] = { 0, 0 };
  119.  
  120. static struct sensemode {
  121.   short status;
  122.   unsigned char xmit_baud;
  123.   unsigned char rcv_baud;
  124.   unsigned char crfill;
  125.   unsigned char lffill;
  126.   unsigned char parity;
  127.   unsigned char unused;
  128.   char class;
  129.   char type;
  130.   short scr_wid;
  131.   unsigned long tt_char : 24, scr_len : 8;
  132.   unsigned long tt2_char;
  133. } sensemode_iosb;
  134.  
  135. #endif
  136.  
  137. /* Generally useful to include this file. */
  138.  
  139. #ifndef INCLUDED_FCNTL
  140. # define INCLUDED_FCNTL
  141. # include <fcntl.h>
  142. #endif /* INCLUDED_FCNTL */
  143.  
  144. /* Formerly there was a conditional that included sys/filio.h if
  145.    USG5_4 was defined, but this is already included in s/usg5-4.h */
  146.  
  147. /* Also this file. */
  148.  
  149. #if !defined (VMS) && !defined (MSDOS) && !defined (WIN32)
  150. # include <sys/ioctl.h>
  151. #endif
  152. /* UNIPLUS systems may have FIONREAD.  */
  153. #ifdef UNIPLUS
  154. #include <sys.ioctl.h>
  155. #endif
  156.  
  157.  
  158. /* ----------------------------------------------------- */
  159. /*                 miscellaneous includes                */
  160. /* ----------------------------------------------------- */
  161.  
  162. #ifdef AIXHFT
  163. /* Get files for keyboard remapping */
  164. #define HFNKEYS 2
  165. #include <sys/hft.h>
  166. #include <sys/devinfo.h>
  167. #endif
  168.  
  169. #ifdef NEED_BSDTTY
  170. #include <sys/bsdtty.h>
  171. #endif 
  172.  
  173. /* Include files for PTY's */
  174.  
  175. #if defined (HPUX) && defined (HAVE_PTYS)
  176. #include <sys/ptyio.h>
  177. #endif
  178.   
  179. #ifdef AIX
  180. #include <sys/pty.h>
  181. #endif /* AIX */
  182.  
  183. #ifdef SYSV_PTYS
  184. # include <sys/types.h>
  185. # include <sys/tty.h>
  186. # ifdef titan
  187. #  include <sys/ttyhw.h>
  188. #  include <sys/stream.h>
  189. # endif
  190. # ifndef NO_PTY_H
  191. #  include <sys/pty.h>
  192. # endif
  193. #endif
  194.  
  195.  
  196. /* ----------------------------------------------------- */
  197. /*           inhibiting particular features              */
  198. /* ----------------------------------------------------- */
  199.  
  200. #ifdef APOLLO
  201. #undef TIOCSTART
  202. #endif
  203.  
  204. #ifdef BROKEN_TIOCGETC
  205. #undef TIOCGETC  /* Avoid confusing some conditionals that test this.  */
  206. #endif
  207.  
  208. #ifdef BROKEN_TIOCGWINSZ
  209. #undef TIOCGWINSZ
  210. #undef TIOCSWINSZ
  211. #endif
  212.  
  213. #ifdef BROKEN_O_NONBLOCK
  214. # undef O_NONBLOCK
  215. #endif /* BROKEN_O_NONBLOCK */
  216.  
  217. /* On TERMIOS systems, the tcmumbleattr calls take care of these
  218.    parameters, and it's a bad idea to use them (on AIX, it makes the
  219.    tty hang for a long time).  */
  220. #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
  221. #define HAVE_LTCHARS
  222. #endif
  223.  
  224. #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
  225. #define HAVE_TCHARS
  226. #endif
  227.  
  228.  
  229. /* ----------------------------------------------------- */
  230. /*             disabling terminal functions              */
  231. /* ----------------------------------------------------- */
  232.  
  233. /* Try to establish the correct character to disable terminal functions
  234.    in a system-independent manner.  Note that USG (at least) define
  235.    _POSIX_VDISABLE as 0!  */
  236.  
  237. #ifdef _POSIX_VDISABLE
  238. #define CDISABLE _POSIX_VDISABLE
  239. #else /* not _POSIX_VDISABLE */
  240. #ifdef CDEL
  241. #undef CDISABLE
  242. #define CDISABLE CDEL
  243. #else /* not CDEL */
  244. #define CDISABLE 255
  245. #endif /* not CDEL */
  246. #endif /* not _POSIX_VDISABLE */
  247.  
  248.  
  249. /* ----------------------------------------------------- */
  250. /*    Get the number of characters queued for output     */
  251. /* ----------------------------------------------------- */
  252.  
  253. /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
  254.    queued for output to the terminal FD in *SIZE, if FD is a tty.
  255.    Returns -1 if there was an error (i.e. FD is not a tty), 0
  256.    otherwise.  */
  257. #ifdef TIOCOUTQ
  258. #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TIOCOUTQ, size)
  259. #endif
  260.  
  261. #ifdef HAVE_TERMIO
  262. #ifdef TCOUTQ
  263. #undef EMACS_OUTQSIZE
  264. #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TCOUTQ, size)
  265. #endif
  266. #endif
  267.  
  268.  
  269. /* -------------------------------------------------------------------- */
  270. /*       Manipulate a terminal's current (foreground) process group     */
  271. /* -------------------------------------------------------------------- */
  272.  
  273. /* EMACS_GET_TTY_PROCESS_GROUP(int FD, int *PGID) sets *PGID the terminal FD's
  274.    current process group.  Return -1 if there is an error.
  275.  
  276.    EMACS_SET_TTY_PROCESS_GROUP(int FD, int *PGID) sets the terminal FD's
  277.    current process group to *PGID.  Return -1 if there is an error.  */
  278.  
  279. #if defined (HAVE_TERMIOS) && ! defined (BSD_TERMIOS)
  280.  
  281. #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) (*(pgid) = tcgetpgrp (fd))
  282. #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) tcsetpgrp (fd, *(pgid))
  283.  
  284. #elif defined (TIOCSPGRP)
  285.  
  286. #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCGPGRP, pgid)
  287. #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCSPGRP, pgid)
  288.  
  289. #else
  290.  
  291. /* Just ignore this for now and hope for the best */
  292. #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) 0
  293. #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgif) 0
  294.  
  295. #endif
  296.  
  297. /* EMACS_GET_PROCESS_GROUP () returns the process group we are running in.  */
  298.  
  299. /* USG systems have always used the no-arg form of getpgrp().
  300.    POSIX also calls for this, and thus some newer BSD systems
  301.    have this change.  Older BSD systems have an argument.
  302.    It would be nice to autodetect this, but there's unfortunately
  303.    no general way. */
  304.  
  305. #if defined (USG) || defined (GETPGRP_NO_ARG)
  306. #  define EMACS_GET_PROCESS_GROUP() getpgrp ()
  307. #else
  308. #  define EMACS_GET_PROCESS_GROUP() getpgrp (0)
  309. #endif /* !GETPGRP_NO_ARG */
  310.  
  311. /* EMACS_SEPARATE_PROCESS_GROUP () creates a separate process group for the
  312.    running process. */
  313.  
  314. /* EMACS_SET_PROCESS_GROUP () sets our process group as specified. */
  315.  
  316. /* POSIX calls for setpgid(), so we use it if it's available.
  317.    Otherwise use setpgrp(), in USG or BSD flavor.  Note that
  318.    on newer systems, setpgrp() has unwanted effects (e.g.
  319.    creating a new session), so we want to avoid its use
  320.    if possible.
  321.  
  322.    NOTE: On some older systems, we should consider using setpgrp2()
  323.    if it exists.  This is sufficiently rare, though, that there
  324.    seems no point in autodetecting it.  Currently dgux.h is the
  325.    only place where this has to be munged. */
  326.  
  327. #if defined (HAVE_SETPGID)
  328. #  define EMACS_SEPARATE_PROCESS_GROUP() setpgid (0, 0)
  329. #  define EMACS_SET_PROCESS_GROUP(pg) setpgid (0, pg)
  330. #elif defined (USG)
  331. #  define EMACS_SEPARATE_PROCESS_GROUP() setpgrp ()
  332. /* old (pre-SVR4) USG's don't provide any way to do this.
  333.    No big loss -- it just means that ^Z won't work right
  334.    if we're run from sh. */
  335. #  define EMACS_SET_PROCESS_GROUP(pg)
  336. #else
  337. /* Under NeXTstep, a process group of 0 is not the same as specifying
  338.    your own process ID, so we go ahead and specify it explicitly. */
  339. #  define EMACS_SEPARATE_PROCESS_GROUP() setpgrp (0, getpid ())
  340. #  define EMACS_SET_PROCESS_GROUP(pg) setpgrp (0, pg)
  341. #endif
  342.  
  343.  
  344. /* --------------------------------------------------------- */
  345. /*   Manipulate a TTY's input/output processing parameters   */
  346. /* --------------------------------------------------------- */
  347.  
  348. /* struct emacs_tty is a structure used to hold the current tty
  349.    parameters.  If the terminal has several structures describing its
  350.    state, for example a struct tchars, a struct sgttyb, a struct
  351.    tchars, a struct ltchars, and a struct pagechars, struct
  352.    emacs_tty should contain an element for each parameter struct
  353.    that Emacs may change.
  354.  
  355.    EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the parameters
  356.    of the tty on FD in *P.  Return zero if all's well, or -1 if we ran
  357.    into an error we couldn't deal with.
  358.  
  359.    EMACS_SET_TTY (int FD, struct emacs_tty *P, int waitp)
  360.    sets the parameters of the tty on FD according to the contents of
  361.    *P.  If waitp is non-zero, we wait for all queued output to be
  362.    written before making the change; otherwise, we forget any queued
  363.    input and make the change immediately.
  364.    Return 0 if all went well, and -1 if anything failed.
  365.  
  366.    EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
  367.    expands tabs to spaces upon output; in that case, there is no
  368.    advantage to using tabs over spaces.  */
  369.  
  370.  
  371.  
  372. /* For each tty parameter structure that Emacs might want to save and restore,
  373.    - include an element for it in this structure, and
  374.    - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
  375.      new members.  */
  376.  
  377. struct emacs_tty {
  378.  
  379. /* There is always one of the following elements, so there is no need
  380.    for dummy get and set definitions.  */
  381. #ifdef HAVE_TCATTR
  382.   struct termios main;
  383. #else
  384. #ifdef HAVE_TERMIO
  385.   struct termio main;
  386. #else
  387. #ifdef VMS
  388.   struct sensemode main;
  389. #else
  390. #ifdef MSDOS
  391.   int main;
  392. #else
  393.   struct sgttyb main;
  394. #endif /* !MSDOS */
  395. #endif /* !VMS */
  396. #endif
  397. #endif
  398.  
  399. /* If we have TERMIOS, we don't need to do this - they're taken care of
  400.    by the tc*attr calls.  */
  401. #ifndef HAVE_TERMIOS
  402. #ifdef HAVE_LTCHARS
  403.   struct ltchars ltchars;
  404. #endif
  405.  
  406. #ifdef HAVE_TCHARS
  407.   struct tchars tchars;
  408.   int lmode;
  409. #endif
  410. #endif
  411. };
  412.  
  413. /* Define EMACS_GET_TTY and EMACS_SET_TTY,
  414.    the macros for reading and setting parts of `struct emacs_tty'.
  415.  
  416.    These got pretty unmanageable (huge macros are hard to debug), and
  417.    finally needed some code which couldn't be done as part of an
  418.    expression, so we moved them out to their own functions in sysdep.c.  */
  419. #define EMACS_GET_TTY(fd, p)        emacs_get_tty (fd, p)
  420. #define EMACS_SET_TTY(fd, p, waitp) emacs_set_tty (fd, p, waitp)
  421.  
  422.  
  423. /* --------------------------------------------------------- */
  424. /*                Define EMACS_TTY_TABS_OK                   */
  425. /* --------------------------------------------------------- */
  426.  
  427. #ifdef HAVE_TERMIOS
  428.  
  429. #ifdef TABDLY
  430. #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
  431. #else
  432. #define EMACS_TTY_TABS_OK(p) 1
  433. #endif
  434.  
  435. #else /* not def HAVE_TERMIOS */
  436. #ifdef HAVE_TERMIO
  437.  
  438. #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
  439.  
  440. #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
  441. #ifdef VMS
  442.  
  443. #define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0)
  444.  
  445. #else
  446.  
  447. #ifdef MSDOS
  448. #define EMACS_TTY_TABS_OK(p) 0
  449. #else /* not MSDOS */
  450. #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS)
  451. #endif /* not MSDOS */
  452.  
  453. #endif /* not def VMS */
  454. #endif /* not def HAVE_TERMIO */
  455. #endif /* not def HAVE_TERMIOS */
  456.  
  457. #endif /* _XEMACS_SYSTTY_H_ */
  458.